<?php

namespace App\Jobs;

use App\Logic\ConfigLogic;
use EasyWeChat\Factory;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class SendWxMessage implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $message;
    protected $open_id;

    /**
     * SendWxMessage constructor.
     * @param $message
     * @param $open_id
     */
    public function __construct($message, $open_id)
    {
        $this->message = $message;
        $this->open_id = $open_id;
    }

    /**
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     */
    public function handle()
    {
        $config = ConfigLogic::getWxConfig();
        $app = Factory::officialAccount($config);
        $re = $app->customer_service->message($this->message)->to($this->open_id)->send();
    }
}
